package main

import (
	"fmt"
	"reflect"
)

func reflectType(x interface{}) {

	//反射
	v := reflect.ValueOf(x)
	fmt.Println(v)
	fmt.Printf("%T\n", v)

	k := v.Kind() //拿到值对应的类型

	switch k {

	case reflect.Float32:
		ret := float32(v.Float())
		fmt.Printf("%T %v", ret, ret)
	case reflect.Int32:
		ret := int64(v.Int())
		fmt.Printf("%T %v", ret, ret)
	case reflect.String:
		fmt.Printf("%T %v", v, v)

	}
}

type Cat struct {
	name string
}

func main() {
	var a int32 = 1
	reflectType(a)

	var b int8 = 1
	reflectType(b)

	c := Cat{
		name: "hello",
	}
	reflectType(c.name)
}
